#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:
    template<typename elem>
    elem maxItem(const std::vector<elem> &raw){
        elem record=raw[0];
        for(int i=0;i<=int(raw.size())-1;i++){
            if(raw[i]>record){
                record=raw[i];
            } 
        }
        return record;
    }

    int rob(const vector<int>& nums) {
        const int n=nums.size();
        if(n<=0){
            return 0;
        }
        if(n==1){
            return nums[0];
        }
        if(n==2){
            return std::max<int>(nums[0],nums[1]);
        }
        
        // n>=3
        std::vector<int> a(n),b(n);
        a[0]=nums[0];
        a[1]=nums[1];
        b[0]=0;
        b[1]=nums[0];

        for(int i=2;i<=n-1;i++){
            a[i]=nums[i]+b[i-1];
            b[i]=std::max<int>(a[i-1],b[i-1]);
        }

        return std::max(
            maxItem<int>(a),maxItem<int>(b)
        );
    }
};

int main(){
    Solution test{};
    const std::vector<int> raw={1,2,3,1};
    std::cout<<test.rob(raw)<<std::endl;
    return 0;
}